<template>
<div class="sub-div">
  <span>父组件传递给子组件2的值是：{{ car }}</span>
  <br/>
  <span>子组件1传递给子组件2的玩具是：{{ toy }}</span>
</div>

</template>
<script setup lang="ts">
import emitter from '@/utils/emitter';
import { onUnmounted, ref } from 'vue';

const car = ref('');
const toy = ref('');

emitter.on('send-car', (value: string) => {
  car.value = value;
});

emitter.on('send-toy', (value: string) => {
  console.log('子组件2接收到玩具：', value);
  toy.value = value;
});

onUnmounted(() => {
  emitter.off('send-car');
  emitter.off('send-toy');
});

</script>
<style lang="scss" scoped>
.sub-div {
  margin-top: 30px;
  padding: 10px 10px;
  color: #42b983;
  font-weight: bold;
  background-color: rgb(15, 105, 184);
}

</style>
